home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-17 | 3.4 KB | 151 lines | [TEXT/PJMM] |
- Unit XPascalIO;
-
- {***************************************************}
- {* }
- {* Some extensions to the Pascal I/O facilities }
- {* to interface them more harmoniously with }
- {* the File Manager. }
- {* }
- {* By Greg Ewing (greg@cosc.canterbury.ac.nz, }
- {* http://www.cosc.canterbury.ac.nz/~greg) }
- {* November 1996 }
- {* Freeware and Use-at-your-own-risk-ware. }
- {* }
- {* Updated to CodeWarrior project, 12/17/96. }
- {* Bill Catambay. }
- {* }
- {***************************************************}
-
- Interface
-
- Uses
- Files, StandardFile, Types;
-
- { FSpReset opens an existing file for reading as Pascal text file, given an FSSpec.}
- Procedure FSpReset (var f: text; spec: FSSpec);
-
- { FSpRewrite creates a new file with the given type and creator codes, and }
- { opens it for writing as a Pascal text file. }
- Procedure FSpRewrite (var f: text; spec: FSSpec; fileType, fileCreator: OSType);
-
- { XIOResult may be called to find out the result of the last call to any of the above }
- { routines. Returns noErr if the call succeeded; otherwise it may return either an }
- { Operating System error code, or a return value from IOResult. }
- Function XIOResult: OSErr;
-
- { GetOldFile prompts the user for the name of an existing file. One file type }
- { may be specified. (If you need to use more than one file type, use StandardGetFile.) }
- Function GetOldFile (fileType: OSType; var spec: FSSpec): boolean;
-
- { GetNewFile prompts the user for the name of a new file. Returns true unless}
- { the dialog is cancelled.}
- Function GetNewFile (prompt, defaultName: Str255; var spec: FSSpec): boolean;
-
-
- Implementation
-
- Var
- gXIOResult: OSErr;
-
- Procedure Ignore (x: univ longint);
-
- begin
- { procedure to ignore function return values }
- end;
-
- Procedure FSpReset (var f: text; spec: FSSpec);
-
- Var
- oldVRefNum: integer;
-
- Procedure Check (result: OSErr);
-
- begin
- if result <> noErr then
- begin
- gXIOResult := result;
- exit(FSpReset);
- end;
- end;
-
- begin {FSpReset}
- gXIOResult := noErr;
- Ignore(GetVol(nil, oldVRefNum));
- Check(HSetVol(nil, spec.vRefNum, spec.parID));
- reset(f, spec.name);
- Check(IOResult);
- Ignore(SetVol(nil, oldVRefNum));
- end;
-
- Procedure FSpRewrite (var f: text; spec: FSSpec; fileType, fileCreator: OSType);
-
- Var
- oldVRefNum: integer;
- info: FInfo;
-
- Procedure Check (result: OSErr);
-
- begin
- if result <> noErr then
- begin
- gXIOResult := result;
- exit(FSpRewrite);
- end;
- end;
-
- begin
- gXIOResult := noErr;
- Ignore(GetVol(nil, oldVRefNum));
- Ignore(HSetVol(nil, spec.vRefNum, spec.parID));
- rewrite(f, spec.name);
- Check(IOResult);
- Check(FSpGetFInfo(spec, info));
- info.fdType := fileType;
- info.fdCreator := fileCreator;
- Check(FSpSetFInfo(spec, info));
- Ignore(SetVol(nil, oldVRefNum));
- end;
-
- Function XIOResult: OSErr;
-
- begin
- XIOResult := gXIOResult;
- end;
-
- Function GetOldFile (fileType: OSType; var spec: FSSpec): boolean;
-
- Var
- reply: StandardFileReply;
- types: SFTypeList;
-
- begin
- types[0] := fileType;
- StandardGetFile(NIL, 1, @types, reply);
- if reply.sfGood then
- begin
- spec := reply.sfFile;
- GetOldFile := true;
- end
- else
- GetOldFile := false;
- end;
-
- Function GetNewFile (prompt, defaultName: Str255; var spec: FSSpec): boolean;
-
- Var
- reply: StandardFileReply;
- types: SFTypeList;
-
- begin
- types[0] := 'TEXT';
- StandardPutFile(prompt, defaultName, reply);
- if reply.sfGood then
- begin
- spec := reply.sfFile;
- GetNewFile := true;
- end
- else
- GetNewFile := false;
- end;
-
- end.